/*
 * @Author: linzeqin
 * @Date: 2019-09-29 14:33:19
 * @description: 沙箱资源调度模块表结构
 */
import { Model, Document, Schema } from './index.d';
import { Application } from 'egg';

export class EnvScript {
    /** 环境 */
    env: string;
    /** 脚本 */
    script: string;
}

/** 项目实体 */
export class SandboxReport {
    /** 名称 */
    name: string = '';

    /** 描述 */
    description: string = '';

    /** 可执行脚本 */
    scriptList: EnvScript[] = [];

    /** 用于预览的路由 */
    route: string = '';

    /** 创建时间 */
    createTime: number = new Date().getTime();

    /** 修改时间 */
    updateTime: number = new Date().getTime();
}

export interface ISandboxReportModel extends Document, SandboxReport {}

export default function SandboxReportModel(
    app: Application,
): Model<ISandboxReportModel> {
    const mongoose = app.mongoose;
    const Schema = mongoose.Schema;
    // @ts-ignore
    const sandboxReportSchema: Schema = new Schema<SandboxReport>({
        name: { type: String, unique: true },
        description: { type: String },
        scriptList: { type: Array },
        route: { type: String },
        createTime: { type: Number },
        updateTime: { type: Number },
    }, {
        timestamps: { updatedAt: 'updateTime', createdAt: 'createTime' },
    });
    return mongoose.model<ISandboxReportModel>(
        'Sandbox_Report',
        sandboxReportSchema,
    );
}
